package com.gomore.opple.data;

import com.gomore.opple.data.local.LocalDataSource;
import com.gomore.opple.data.remote.RemoteDataSource;
import com.gomore.opple.data.remote.bean.WrapperResponseEntity;
import com.gomore.opple.data.remote.bean.result.WeChatResult;
import com.gomore.opple.model.ActionResult;
import com.gomore.opple.model.ShippingAddressEntity;
import com.gomore.opple.model.StoreAddress;
import com.gomore.opple.rest.applybill.ApplyRequest;
import com.gomore.opple.rest.applybill.EarningsResponse;
import com.gomore.opple.rest.applybill.RsApplyBillRequest;
import com.gomore.opple.rest.applybill.RsApplyBillResponse;
import com.gomore.opple.rest.applybill.RsCommissionRequest;
import com.gomore.opple.rest.applybill.RsCommissionResponse;
import com.gomore.opple.rest.applybill.TOBankBindEntity;
import com.gomore.opple.rest.applybill.TOCommAuthEntity;
import com.gomore.opple.rest.consumer.ConsumerDesignerPageResult;
import com.gomore.opple.rest.consumer.ConsumerPageResult;
import com.gomore.opple.rest.consumer.ConsumerQueryCondition;
import com.gomore.opple.rest.employee.LoginInfo;
import com.gomore.opple.rest.employee.LoginResult;
import com.gomore.opple.rest.employee.ModifyPasswordRequest;
import com.gomore.opple.rest.employee.ResetPasswordRequest;
import com.gomore.opple.rest.employee.RsEmployeeRequest;
import com.gomore.opple.rest.goods.GoodsCondition;
import com.gomore.opple.rest.goods.GoodsFilter;
import com.gomore.opple.rest.goods.GoodsResponse;
import com.gomore.opple.rest.hottag.HotFilter;
import com.gomore.opple.rest.jdecard.RsJingDongECardRequest;
import com.gomore.opple.rest.jdecard.RsJingDongECardResponse;
import com.gomore.opple.rest.lottery.Draw;
import com.gomore.opple.rest.lottery.RsLotteryRequest;
import com.gomore.opple.rest.lottery.RsLotteryResponse;
import com.gomore.opple.rest.order.OrderBill;
import com.gomore.opple.rest.order.OrderFilter;
import com.gomore.opple.rest.order.OrderPayRequest;
import com.gomore.opple.rest.order.OrderResponse;
import com.gomore.opple.rest.order.RsOrderShareResponse;
import com.gomore.opple.rest.redPackage.RedPackageResponse;
import com.gomore.opple.rest.redPackage.RsRedPackageConditions;
import com.gomore.opple.rest.shopcart.DeleteCartRequest;
import com.gomore.opple.rest.shopcart.SaveShoppingCartRequest;
import com.gomore.opple.rest.shopcart.ShopCartFilter;
import com.gomore.opple.rest.shopcart.ShopCartResponse;
import com.gomore.opple.web.cgform.app.entity.TOAppversionEntity;
import com.gomore.opple.web.cgform.applybill.entity.TOApplyBillEntity;
import com.gomore.opple.web.cgform.consumer.entity.TOConsumerEntity;
import com.gomore.opple.web.cgform.goods.entity.TOGoodsEntity;
import com.gomore.opple.web.cgform.orderpromotion.entity.TOOrderPromotionEntity;
import com.gomore.opple.web.cgform.resellerstore.entity.TOResellerstoreEntity;
import com.gomore.opple.web.cgform.resellerstore.entity.ToStoreAddress;
import com.gomore.opple.web.cgform.shippingaddr.entity.TOShippingAddrEntity;
import com.gomore.opple.web.system.pojo.TOReseller;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

import okhttp3.MultipartBody;
import retrofit2.Call;
import rx.Observable;

@Singleton
public class DataRepository implements DataSource {
    /**
     * 本地数据仓库
     */
    private final LocalDataSource mLocalDataSource;
    /**
     * 远程数据仓库
     */
    private final RemoteDataSource mRemoteDataSoucre;

    @Inject
    DataRepository(@Local LocalDataSource localDataSource, @Remote RemoteDataSource remoteDataSource) {
        mLocalDataSource = localDataSource;
        mRemoteDataSoucre = remoteDataSource;
    }

    /**
     * 保存用户名到本地仓库
     *
     * @param userName
     */
    @Override
    public void saveUserName(String userName) {
        mLocalDataSource.saveUserName(userName);
    }

    /**
     * 从本地仓库获取用户名
     *
     * @return
     */
    @Override
    public String getUserName() {
        return mLocalDataSource.getUserName();
    }

    /**
     * 保存密码到本地仓库
     *
     * @param passWord
     */
    @Override
    public void savePassWord(String passWord) {
        mLocalDataSource.savePassWord(passWord);
    }

    /**
     * 从本地仓库获取密码
     *
     * @return
     */
    @Override
    public String getPassWord() {
        return mLocalDataSource.getPassWord();
    }


    /**
     * 保存登陆信息
     */
    @Override
    public void saveUser(LoginResult user) {
        mLocalDataSource.saveUser(user);
    }

    /**
     * 获取登陆信息
     *
     * @return
     */
    @Override
    public LoginResult getUser() {
        return mLocalDataSource.getUser();
    }

    @Override
    public void saveConsumer(TOConsumerEntity toConsumerEntity) {
        mLocalDataSource.saveConsumer(toConsumerEntity);
    }

    @Override
    public TOConsumerEntity getConsumer() {
        return mLocalDataSource.getConsumer();
    }

    @Override
    public void clearConsumer() {
        mLocalDataSource.clearConsumer();
    }

    @Override
    public void saveAppVersion(String version) {
        mLocalDataSource.saveAppVersion(version);
    }

    @Override
    public String getAppVersion() {
        return mLocalDataSource.getAppVersion();
    }

    /**
     * 清除等地sharepreference数据
     */
    @Override
    public void clearMessage() {
        mLocalDataSource.clearMessage();
    }

    /**
     * 获取搜索关键字
     *
     * @return
     */

    @Override
    public List<String> getSearchKey() {
        return mLocalDataSource.getSearchKey();
    }

    /**
     * 保存搜索关键字
     *
     * @param keys
     */
    @Override
    public void saveSearchKey(List<String> keys) {
        mLocalDataSource.saveSearchKey(keys);
    }

    @Override
    public void clearHistory() {
        mLocalDataSource.clearHistory();
    }

    /**
     * 升级接口
     *
     * @param apptype
     * @param version
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOAppversionEntity>> checkUpdate(String apptype, String version) {
        return mRemoteDataSoucre.checkUpdate(apptype, version);
    }

    /**
     * 登录请求
     *
     * @param loginInfo
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<LoginResult>> login(LoginInfo loginInfo) {
        return mRemoteDataSoucre.login(loginInfo);
    }

    /**
     * 重置密码
     *
     * @param resetPasswordRequest
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> restPassword(ResetPasswordRequest resetPasswordRequest) {
        return mRemoteDataSoucre.restPassword(resetPasswordRequest);
    }

    /**
     * 发送验证码
     *
     * @param mobilephone
     * @param username
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> sendCode(String mobilephone, String username) {
        return mRemoteDataSoucre.sendCode(mobilephone, username);
    }

    /**
     * 同步登录请求
     *
     * @param loginInfo
     * @return
     */
    @Override
    public Call<WrapperResponseEntity<LoginResult>> loginSyn(LoginInfo loginInfo) {
        return mRemoteDataSoucre.loginSyn(loginInfo);
    }

    /**
     * 获取客户
     *
     * @param consumerQueryCondition
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<ConsumerDesignerPageResult>> getConsumer(ConsumerQueryCondition consumerQueryCondition) {
        return mRemoteDataSoucre.getConsumer(consumerQueryCondition);
    }

    /**
     * 保存客户访问时间
     *
     * @param consumerId
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveLastVisitedTime(String consumerId) {
        return mRemoteDataSoucre.saveLastVisitedTime(consumerId);
    }

    /**
     * 保存客户
     *
     * @param toConsumerEntity
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> save(TOConsumerEntity toConsumerEntity) {
        return mRemoteDataSoucre.save(toConsumerEntity);
    }

    @Override
    public Observable<WrapperResponseEntity<GoodsResponse>> queryGoods(GoodsCondition goodsCondition) {
        return mRemoteDataSoucre.queryGoods(goodsCondition);
    }

    /**
     * 获取所有查询条件
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<GoodsFilter>> getGoodsFilter() {
        return mRemoteDataSoucre.getGoodsFilter();
    }

    /**
     * 获取单个商品
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOGoodsEntity>> getGoodById(String goodId) {
        return mRemoteDataSoucre.getGoodById(goodId);
    }

    /**
     * 添加到购物车
     *
     * @param saveShoppingCartRequest
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> addToShoppingCar(SaveShoppingCartRequest saveShoppingCartRequest) {
        return mRemoteDataSoucre.addToShoppingCar(saveShoppingCartRequest);
    }

    /**
     * 获取热门推荐
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<HotFilter>> getHotTag() {
        return mRemoteDataSoucre.getHotTag();
    }

    /**
     * 查询购物车
     *
     * @param shopCartFilter
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<ShopCartResponse>> queryShoppingCar(ShopCartFilter shopCartFilter) {
        return mRemoteDataSoucre.queryShoppingCar(shopCartFilter);
    }

    @Override
    public Observable<WrapperResponseEntity<String>> updateCostPrice(String cartId, String costPrice, String goodsId, String goodsNum) {
        return mRemoteDataSoucre.updateCostPrice(cartId, costPrice, goodsId, goodsNum);
    }

    /**
     * 删除购物车
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> deleteShoppingCar(DeleteCartRequest deleteCartRequest) {
        return mRemoteDataSoucre.deleteShoppingCar(deleteCartRequest);
    }

    /**
     * 查询收货地址
     *
     * @return
     */

    @Override
    public Observable<WrapperResponseEntity<ShippingAddressEntity>> getShippingAddress(String consumerUuid) {
        return mRemoteDataSoucre.getShippingAddress(consumerUuid);
    }

    /**
     * 保存收货地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveShippingAddress(TOShippingAddrEntity toShippingAddrEntity) {
        return mRemoteDataSoucre.saveShippingAddress(toShippingAddrEntity);
    }

    /**
     * 更新收货地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> updateShippingAddress(TOShippingAddrEntity toShippingAddrEntity) {
        return mRemoteDataSoucre.updateShippingAddress(toShippingAddrEntity);
    }

    /**
     * 删除收货地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> removeShippingAddress(String shippingUuid) {
        return mRemoteDataSoucre.removeShippingAddress(shippingUuid);
    }

    /**
     * 保存订单
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveOrder(OrderBill orderBill) {
        return mRemoteDataSoucre.saveOrder(orderBill);
    }

    /**
     * 获取订单
     *
     * @param order_number
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<OrderBill>> getOrderByNumber(String order_number) {
        return mRemoteDataSoucre.getOrderByNumber(order_number);
    }

    /**
     * 上传附件
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> uploadAttachment(MultipartBody.Part file) {
        return mRemoteDataSoucre.uploadAttachment(file);
    }

    /**
     * 获取促销结果
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<ActionResult>> getCalc(String orderNumber) {
        return mRemoteDataSoucre.getCalc(orderNumber);
    }

    /**
     * 获取经营者二维码
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOReseller>> getReseller() {
        return mRemoteDataSoucre.getReseller();
    }

    /**
     * 支付订单
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> payOrder(OrderPayRequest orderPayRequest) {
        return mRemoteDataSoucre.payOrder(orderPayRequest);
    }

    /**
     * 分享订单
     *
     * @param order_number
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsOrderShareResponse>> orderShare(String order_number) {
        return mRemoteDataSoucre.orderShare(order_number);
    }

    /**
     * 修改订单状态
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> updateOrderState(String order_number, String oldstate, String newstate) {
        return mRemoteDataSoucre.updateOrderState(order_number, oldstate, newstate);
    }

    /**
     * 获取我的信息
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<EarningsResponse>> getTotal(String employeeId) {
        return mRemoteDataSoucre.getTotal(employeeId);
    }

    /**
     * 验证银行卡
     *
     * @param toCommAuthEntity
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> commAuth(TOCommAuthEntity toCommAuthEntity) {
        return mRemoteDataSoucre.commAuth(toCommAuthEntity);
    }

    /**
     * 、
     * 绑定银行卡
     *
     * @param toBankBindEntity
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> bind(TOBankBindEntity toBankBindEntity) {
        return mRemoteDataSoucre.bind(toBankBindEntity);
    }

    /**
     * 绑定银行卡，发送验证码
     *
     * @param mobilephone
     * @param username
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> bankCardBindSendSms(String mobilephone, String username) {
        return mRemoteDataSoucre.bankCardBindSendSms(mobilephone, username);
    }

    /**
     * 解绑银行卡
     *
     * @param bankAccount
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> unbind(String bankAccount) {
        return mRemoteDataSoucre.unbind(bankAccount);
    }

    /**
     * 提现申请保存
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> applySave(ApplyRequest applyRequest) {
        return mRemoteDataSoucre.applySave(applyRequest);
    }

    /**
     * 查询收支明细
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsCommissionResponse>> queryIncomeAndExpense(RsCommissionRequest rsCommissionRequest) {
        return mRemoteDataSoucre.queryIncomeAndExpense(rsCommissionRequest);
    }

    /**
     * 查询提现进度明细
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsApplyBillResponse>> queryApply(RsApplyBillRequest rsApplyBillRequest) {
        return mRemoteDataSoucre.queryApply(rsApplyBillRequest);
    }

    /**
     * 查询京东E卡
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsJingDongECardResponse>> queryJDE(RsJingDongECardRequest rsJingDongECardRequest) {
        return mRemoteDataSoucre.queryJDE(rsJingDongECardRequest);
    }

    /**
     * 激活京东E卡
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> activeJDE(String orderNumber, String orderReceiptUrl) {
        return mRemoteDataSoucre.activeJDE(orderNumber, orderReceiptUrl);
    }

    /**
     * 使用京东E卡
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> useJDE(String cardNumber) {
        return mRemoteDataSoucre.useJDE(cardNumber);
    }

    /**
     * 查询我的抽奖
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsLotteryResponse>> queryAward(RsLotteryRequest rsLotteryRequest) {
        return mRemoteDataSoucre.queryAward(rsLotteryRequest);
    }

    /**
     * 去抽奖
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> drawAward(Draw draw) {
        return mRemoteDataSoucre.drawAward(draw);
    }

    /**
     * 查询红包
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RedPackageResponse>> queryRedPackage(RsRedPackageConditions rsRedPackageConditions) {
        return mRemoteDataSoucre.queryRedPackage(rsRedPackageConditions);
    }

    /**
     * 激活红包
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> activeRedPackage(String orderNumber, String orderReceiptUrl) {
        return mRemoteDataSoucre.activeRedPackage(orderNumber, orderReceiptUrl);
    }

    /**
     * 查询订单
     *
     * @param orderFilter
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<OrderResponse>> queryOrder(OrderFilter orderFilter) {
        return mRemoteDataSoucre.queryOrder(orderFilter);
    }

    /**
     * 退出登录
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> logout() {
        return mRemoteDataSoucre.logout();
    }

    /**
     * 修改密码
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> modifyPassword(ModifyPasswordRequest modifyPasswordRequest) {
        return mRemoteDataSoucre.modifyPassword(modifyPasswordRequest);
    }

    /**
     * 保存门店代码
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveResellerStore(TOResellerstoreEntity toResellerstoreEntity) {
        return mRemoteDataSoucre.saveResellerStore(toResellerstoreEntity);
    }

    /**
     * 保存门店地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveStoreAddress(ToStoreAddress toStoreAddress) {
        return mRemoteDataSoucre.saveStoreAddress(toStoreAddress);
    }

    /**
     * 获取购物车数量
     *
     * @param consumerId
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> getShoppingCarNumber(String consumerId) {
        return mRemoteDataSoucre.getShoppingCarNumber(consumerId);
    }

    /**
     * 使用微信卡卷
     *
     * @param voucherNo
     * @param orderNum
     * @param orderTotal
     * @return
     */
    @Override
    public Observable<WeChatResult> getWeChat(String voucherNo, String orderNum, String orderTotal) {
        return mRemoteDataSoucre.getWeChat(voucherNo, orderNum, orderTotal);
    }

    /**
     * 通过条形码获取商品
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOGoodsEntity>> getGoodsByCode(String barcode) {
        return mRemoteDataSoucre.getGoodsByCode(barcode);
    }

    /**
     * 修改员工资料
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> updateEmployee(RsEmployeeRequest rsEmployeeRequest) {
        return mRemoteDataSoucre.updateEmployee(rsEmployeeRequest);
    }

    /**
     * 获取提现进度明细
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOApplyBillEntity>> getDetailState(String uuid) {
        return mRemoteDataSoucre.getDetailState(uuid);
    }

    /**
     * 促销记录
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<List<TOOrderPromotionEntity>>> getOrderPromotion(String orderNumber) {
        return mRemoteDataSoucre.getOrderPromotion(orderNumber);
    }

    /**
     * 获取门店地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<StoreAddress>> getStoreAddress(String currentDepartId) {
        return mRemoteDataSoucre.getStoreAddress(currentDepartId);
    }
}
